
#include <BReadWrite>
#include <BApplication>

#include "HistoryDialog.h"
#include "MainDialog.h"

#ifdef BWE_RELEASE
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
#endif

int main(int argc, char** argv)
{
	BApplication app(argc, argv);
	app.setStyleSheet("style.css");

	BString fileName;
	if (argc > 1)
	{
		fileName = app.argv(1);
	}
	else
	{
		HistoryDialog* historyDialog = new HistoryDialog();
		if (!historyDialog->empty())
		{
			Button result = historyDialog->execute();
			if (result == Button_None)
				return 0;
			if (result == Button_Open)
				fileName = (const BString&)historyDialog->property("file");
		}
		app.setProperty("history-dialog", historyDialog);
	}

	MainDialog* dialog = new MainDialog();
	dialog->setTitle(u8"笔记本");
	dialog->setSize(1200, 700);
	dialog->show();

	if (fileName.size())
	{
		if (dialog->openFile(fileName))
		{
			dialog->setTitle(fileName.name());
		}
	}

	return app.execute();
}